<script type="text/javascript">
    $(function() {
        $("#valor").maskMoney({decimal: ",", thousands: "."});
        $('#vencimento').mask('99/99/9999');
    });
</script>
<center>
    <?php echo $this->view->menssagem; ?>
    <div class="panel panel-default" style="width: 600px">
        <div class="panel-heading" style="text-align: center;font-weight: bold;">Baixa de Contas a pagar</div>
        <div class="panel-body">
            <form class="form-horizontal" role="form" method="post" action="/caixa/conta_baixa">
                <?php if ($this->view->exibir) { ?>
                    <div class="form-group">
                        <label for="nr_label" class="col-sm-4 control-label">Conta:</label>
                        <div class="col-sm-4" style="text-align: right">
                            <span id="nr_label" ><?php echo $this->view->conta['numero_documento']; ?>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="venc_label" class="col-sm-4 control-label">vencimento:</label>
                        <div class="col-sm-4" style="text-align: right">
                            <span id="venc_label"><?php echo \SON\UTIL\Converter::dataParaString($this->view->conta['vencimento']); ?></span>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="vr_label" class="col-sm-4 control-label">Valor:</label>
                        <div class="col-sm-4" style="text-align: right">
                            <span id="vr_label" ><?php echo "R$ " . \SON\UTIL\Converter::doubleParaString($this->view->conta['valor']); ?></span>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="vrp_label" class="col-sm-4 control-label">Valor Pago:</label>
                        <div class="col-sm-4" style="text-align: right">
                            <span id="vrp_label" ><?php echo "R$ " . \SON\UTIL\Converter::doubleParaString($this->view->valor_pago - 0); ?></span>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="sal_label" class="col-sm-4 control-label">Saldo Devedor:</label>
                        <div class="col-sm-4" style="text-align: right">
                            <span id="sal_label" ><?php echo "R$ " . \SON\UTIL\Converter::doubleParaString($this->view->conta['valor'] - $this->view->valor_pago); ?></span>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="st_label" class="col-sm-4 control-label">Status:</label>
                        <div class="col-sm-4" style="text-align: right">
                            <span id="st_label"><?php echo $this->view->conta['status']; ?></span>
                            <span ><?php echo "<input type='hidden' name='id' value='" . $this->view->conta['id'] . "' />"; ?></span>
                        </div>
                    </div>
                <?php } ?>
                <div class="form-group">
                    <label for="valor" class="col-sm-4 control-label">Valor da baixa</label>
                    <div class="col-sm-4">
                        <input class="form-control" type="text" name="valor" size="30" placeholder="Valor a dar baixa" id="valor"/>
                    </div>
                </div>
                <div align="right" class="col-sm-offset-2 col-sm-10">
                    <button class="btn btn-primary" type="submit" ><span class="glyphicon glyphicon-floppy-disk"></span> Baixar</button>
                </div>
            </form>
        </div>
    </div>
    <h3>Parcelas</h3>
    <table class="table table-striped table-hover" >
        <thead>
            <tr>
                <th>Parcela</th>
                <th>Valor</th>
                <th>Data da Baixa</th>
                <th>Ações</th>
            </tr>
        </thead>
        <tbody>
            <?php
            foreach ($this->view->parcelas as $c) {
                echo '<tr>';
                echo '<td>';
                echo $c['parcela'];
                echo '</td>';
                echo '<td>';
                echo \SON\UTIL\Converter::doubleParaString($c['valor']);
                echo '</td>';
                echo '<td>';
                echo \SON\UTIL\Converter::dataTimeParaString($c['data_baixa']);
                echo '</td>';
                echo '<td>';
                if ($this->view->conta['status'] == 'Aberto') {
                    echo "<form method='post' action='/caixa/conta_exclui_parcela_2'>";
                    echo "<input  name='id' value='{$c['conta']}' type='hidden'></input> ";
                    echo "<input  name='id_parcela' value='{$c['parcela']}' type='hidden'></input>";
                    echo "<button class=\"btn btn-default\" type=\"submit\"><span class=\"glyphicon glyphicon-floppy-remove\"></span> Excluir</button>";
                    echo '</form>';
                }
                echo '</td>';
                echo '</tr>';
            }
            ?>
        </tbody>
    </table>
</center>